document.writeln('<link rel="stylesheet" type="text/css" media="screen" href="/ASTACALA/res/jquery-ui-1.9.1.custom/css/smoothness/jquery-ui-1.9.1.custom.min.css" />');
document.writeln('<link rel="stylesheet" type="text/css" media="screen" href="/ASTACALA/res/jqgrid/css/ui.jqgrid.css" />');
document.writeln('<script src="/ASTACALA/res/jqgrid/js/jquery-1.7.2.min.js" type="text/javascript" />');
document.writeln('<script src="/ASTACALA/res/jquery-ui-1.9.1.custom/js/jquery-ui-1.9.1.custom.min.js" />');
document.writeln('<script src="/ASTACALA/res/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript" />');
document.writeln('<script src="/ASTACALA/res/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript" />');

function loadGridData(grid, result) {
    columnData = result.dataMap;
    columnNames = result.colNames;
    columnModel = result.colModel;                                                           
    grid.jqGrid({                   
        url : result.gridUrl,
        data:columnData.datagrid,
        datatype: 'local',                  
        colNames:columnNames,                   
        colModel:columnModel,
        rowNum:10,
        rownumbers: true,
        gridview : true,
        rowList:[10,20,30],
        height:'auto',
        width:'auto',
        pager: jQuery('#gridpager'),
        viewrecords: true
    });    
                        
    grid.jqGrid('filterToolbar',{
        searchOnEnter: true, 
        enableClear: true
    });    
}

function myReloadGrid(grid, result){
    columnData = result.dataMap;
    grid
    .jqGrid('setGridParam',
    { 
        datatype: 'local',
        data:columnData.datagrid
    })
    .trigger("reloadGrid");
}

function addGrid(grid, id) {
    grid.jqGrid('editGridRow', 'new', {
        modal : true,
        url : '/ASTACALA/form/addForm',
        closeAfterAdd: true,
        reloadAfterSubmit:true,
        afterSubmit:function (response, postdata) {
            
            return [true,''];
        }
    } );
}

function editGrid(grid, id) {
    grid.jqGrid('editGridRow', id, {
        modal : true,
        url : '/ASTACALA/form/editForm',
        drag:false,
        closeAfterEdit:true,
        reloadAfterSubmit:true,
        afterSubmit:function (response, postdata) {
            
            return [true,'',id];
        }
    });
}
            
function deleteGrid(grid, id) {
    grid.jqGrid('delGridRow', id, {
        modal : true,
        url : '/ASTACALA/form/deleteForm',
        closeAfterEdit:true,
        afterSubmit:function (response, postdata) {
            
            return [true,''];
        }
    } );
} 

function searchPro(grid, key, keyVal) {      
    jQuery.ajax({
        url : '/ASTACALA/form/searchForm',
        type: 'post',
        data: {
            key:key, 
            keyvalue:keyVal
        },          
        dataType: "json",
        success : function (result) {    
            grid.jqGrid().clearGridData(true);            
            myReloadGrid(grid.jqGrid(), result);
        }                    
    });
}

function exportPro(ep) {
    ep.click(function(event){
        alert('export');
    });
}

function importPro(dPicker) {
    dPicker.click(function(event){
        alert('import');
    });
}